package com.project.pet.pojo;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;


public class UserDetailsImpl implements UserDetails {
    private static final long serialVersionUID = 3195355948584649293L;

    private Integer id;

    private String role;

    public String getRole() {
        return role;
    }

    public Integer getId() {
        return id;
    }

    private Set<GrantedAuthority> authorities = new HashSet<>();

    private String userName;

    private String password;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public UserDetailsImpl(User user){
        this.id = user.getId();
        this.userName = user.getUsername();
        this.password = user.getPassword();
        this.role = user.getRole();
        this.authorities.add(new SimpleGrantedAuthority(this.role));
    }

}
